{include file="public/toper" /}
<style>
    .layui-table-cell {
        font-size:14px;
        padding:0 5px;
        height:auto;
        overflow:visible;
        text-overflow:inherit;
        white-space:normal;
        word-break: break-all;
    }
    .layui-table-fixed {display: none;}
</style>
    <div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">订单管理</a>
        <a><cite>订单信息</cite></a>
      </span>
      <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
    </div>
    <div class="x-body">
        <div class="layui-row">
            <div class="layui-form layui-col-md12 x-so">
              <div class="layui-input-inline">
                <input type="text" name="order_sn" value=""  placeholder="请输入订单编号"  autocomplete="off" class="layui-input"> 
              </div>
              <div class="layui-input-inline">
                <input type="text" name="user_name" value=""  placeholder="请输入姓名"  autocomplete="off" class="layui-input"> 
              </div>
              <div class="layui-input-inline">
                <input type="text" name="phone" value=""  placeholder="请输入电话"  autocomplete="off" class="layui-input"> 
              </div>
              <div class="layui-input-inline">
                  <select name="order_status" lay-filter="aihao" id="orderStatus">
                      <option value="">请选择订单状态</option>
                      <option value="1000">未付款</option>
                      <option value="1">已付款</option>
                      <option value="2">已发货</option>
                      <option value="3">已完成</option>
                      <option value="4">已取消</option>
                      <option value="5">归还中</option>
                      <option value="6">店铺已收货</option>
                      <option value="7">已验收</option>
                      <option value="8">待用户确认</option>
                      <option value="9">待用户支付</option>
                      <option value="10">租赁中</option>
                  </select>
              </div>
              <div class="layui-input-inline">
                  <input class="layui-input" placeholder="开始日期" name="date_start" id="start" value="">
              </div>
              <div class="layui-input-inline">
                  <input class="layui-input" placeholder="截止日期" name="date_end" id="end" value="">
              </div>
              <button class="layui-btn" id="search"><i class="layui-icon">&#xe615;</i></button>
            </div>
        </div>
        <table class="layui-hide" id="test" lay-filter="test"></table>
    </div>
 

<script type="text/html" id="barDemo">
    {{# if(d.order_status === '已付款'){ }}
    <button title="出货" class="layui-btn layui-btn-xs" onclick="x_admin_show('出货','/merchant/Order/orderDetail?id={{d.order_id}}','700')" href="javascript:;" lay-event="edit">出货</button>
    {{# } }}

    {{# if(d.order_status === '归还中'){ }}
    <a id="{{d.order_id}}" lay-event="edits"  class="layui-btn layui-btn-xs" title="收货">收货</a>
    {{# } }}

    {{# if(d.order_status === '店铺已收货' && d.business_pay===0 || d.order_status === '待用户确认' && d.business_pay===0){ }}
    <button title="商品质检" class="layui-btn layui-btn-xs" onclick="x_admin_show('商品质检','/merchant/Order/quality?id={{d.order_id}}')" href="javascript:;">商品质检</button>
    {{# } }}

    {{# if(d.type === 1 && d.order_status === '待用户确认' ||d.type === 1 && d.order_status === '待用户支付' ||d.type === 1 && d.order_status === '已完成'){ }}
    <button title="查看" class="layui-btn layui-btn-xs" onclick="x_admin_show('查看','/merchant/Order/details?id={{d.order_id}}')" href="javascript:;" >查看</button>
    {{# } }}

</script>
<script type="text/html" id="sn">
    <div><a href="{:url('Order/orderInfo')}?id={{d.order_id}}" title="查看详情" class="layui-table-link">{{d.order_sn}}</a></div>
    <div>{{#  if(d.type==1){ }}
        会员订单
        {{#  } else if(d.type==2) { }}
        销售订单
        {{#  } }}
    </div>
</script>
<script type="text/html" id="shou">
    {{#  if(d.order_type=='快递'){ }}
    【快递】：{{d.name}},{{d.phone}}
    <span>{{d.consignee}}</span>
    {{#  } else if(d.order_type=='自提') { }}
    【自提】：{{d.sname}},{{d.sphone}}<span>{{d.saddress}}</span>
    {{#  } }}
</script>
<script type="text/html" id="goodsp">
    <div>{{d.goods_price}}</div>
    {{# if(d.type==1){ }}<div>邮费：{{d.postage}}</div><div>押金：{{d.deposit_price}}</div>{{#} }}
</script>
<script type="text/html" id="payp">
    <div>{{d.pay_price}}</div>{{# if(d.type==1){ }}<div>邮费：{{d.postage}}</div><div>押金：{{d.deposit_price}}</div> {{#} }}
</script>
<script type="text/html" id="date">
    {{#  if(d.type==1){ }}
    {{d.lease_time}}/{{d.lease_end_time}}

    {{#  } else if(d.type==2) { }}
    {{d.confirm_time}}
    {{#  } }}
</script>
    <script>
        layui.use(['table','laydate','laytpl'], function(){
            var table = layui.table
            ,form = layui.form
            ,laydate = layui.laydate
            ,laytpl = layui.laytpl
            ,$ = layui.jquery;

            //执行一个laydate实例
            laydate.render({
              elem: '#start' //指定元素
            });

            //执行一个laydate实例
            laydate.render({
              elem: '#end' //指定元素
            });
          
            var tableIn = table.render({
                method: 'post',
                elem: '#test'
                ,url:"{:url('Order/orderList')}"
                ,cellMinWidth: 80
                ,cols: [[
                    {type:'numbers'}
                    ,{field:'order_sn', width:190, title: '订单编号',align: 'center',templet:'#sn'}
                    ,{width:300,title: '收货信息',align: 'center',templet: '#shou'}
                    ,{width:130,title:'订单金额',align:'center',templet:'#goodsp'}
                    ,{width:130,title:'实付金额',align:'center',templet:'#payp'}
                    ,{width:150,title:'用户收货日期/归还日期',align:'center',templet:'#date'}
                    ,{field:'add_time', title:'下单时间', align:'center',width:200}
                    ,{field:'order_status', title:'订单状态', align:'center',width:200}
                    ,{fixed: 'right', title:'操作', width:150, align:'center', toolbar: '#barDemo'} //这里的toolbar值是模板元素的选择器
                ]]
                ,page: true
            });

            //搜索
            $('#search').on('click', function () {
                var order_sn = $("input[name='order_sn']").val();
                var user_name = $("input[name='user_name']").val();
                var phone = $("input[name='phone']").val();
                var order_status = $('#orderStatus option:selected').val();
                var date_start = $("input[name='date_start']").val();
                var date_end = $("input[name='date_end']").val();
                tableIn.reload({
                    where: {
                      order_sn:order_sn
                      ,user_name:user_name
                      ,phone:phone
                      ,order_status:order_status
                      ,date_start:date_start
                      ,date_end:date_end
                    }
                });
            });




            table.on('tool(test)', function(obj) {
                var data = obj.data;
                if(obj.event === 'edits'){
                    layer.confirm('您确定要收货吗？',{btnAlign: 'c'}, function(index){
                        var loading = layer.load(1, {shade: [0.1, '#fff']});
                        $.get("{:url('Order/collect')}",{id:data.order_id,type:data.return_type},function(res){
                            layer.close(loading);
                            if(res.code==200){
                                layer.msg(res.msg,{time:1000,icon:1});
                                tableIn.reload();
                            }else{
                                layer.msg(res.msg,{time:1000,icon:2});
                            }
                        });
                        layer.close(index);
                        layer.closeAll();
                    });

                }
            });

        });
    </script>
  </body>

</html>